package com.ttbj.controller.systemlog;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ttbj.api.dto.Page;
import com.ttbj.api.dto.log.SystemLogDto;
import com.ttbj.api.exception.BusinessException;
import com.ttbj.api.systemlog.SystemLogService;
import com.ttbj.util.ViewDataUtil;

@Controller
public class SystemLogController {
	
	
	@Autowired
	private SystemLogService systemLogService; 
	
	/**
	 * 日志页面
	 * @return
	 */
	@RequestMapping(value="/log/system_log.htm")
	public String system_log() {
		return "systemlog/systemlog";
	}
	
	
	/**
	 * 查询所有的系统日志
	 * @param type 日志类型，0为系统操作，1为系统异常
	 * @param page 分页信息
	 * @return
	 */
	@RequestMapping(value="/log/getOperationOrExceptionLog.htm", method=RequestMethod.POST, produces={"text/html;charset=UTF-8;","application/json;"})
	@ResponseBody
	public String getOperationOrExceptionLog(@RequestParam Integer type, Page page) {
		try {
			List<SystemLogDto> systemLogDtos = this.systemLogService.findOperationOrExceptionLog(type, page);
			int count = 0;
			if (systemLogDtos != null) {
				count = this.systemLogService.findOperationOrExceptionLogCount(type);
			}
			return ViewDataUtil.buildSuccessPageJson("日志", systemLogDtos, count);
		} catch (BusinessException e) {
			return ViewDataUtil.buildFailureJson(e.getErrorCode(), e.getMessage());
		}
	}
}
